<?php
/**
 *	[TWCMS] (C)2012 TongWang Inc.
 *	$Id: category_model.tpl.php 2 2013-04-27 07:14:17Z nanown@qq.com $
 */
	defined('IN_TWCMS') || exit('Access Denied');
	include load_tpl('head');
?>
	<div class="head">
		<dl>
			<input id="add" type="button" value="增加模型" class="but1" />
			<dd class="on"><?php echo $this->title?></dd>
		</dl>
	</div>
	
	<div class="p c2">
		<div class="cc">
			<table class="tb2">
				<thead>
					<tr class="tit">
						<th width="50">模型ID</th>
						<th width="150">模型操作</th>
						<th>模型名称</th>
						<th>模型数据表</th>
						<th>模型类型</th>
					</tr>
				</thead>
				<tbody></tbody>
			</table>
		</div>
	</div>
</div>
<div id="add_edit">
	<form action="" method="POST">
		<table class="tb">
			<tr>
				<th>模型名称</th>
				<td><input name="name" type="text" class="inp w1" /></td>
			</tr>
			<tr>
				<th>数据表名</th>
				<td><input name="tablename" type="text" class="inp w1" /></td>
			</tr>
		</table>
	</form>
</div>
<script type="text/javascript">
_getBody();
$("#add_edit").twdialog({title:$("#add").val(), resizable:false, open:false, width:400, height:155, minW:400});

twAjax.submit("form:first", function(data){
	twAjax.alert(data);
	if(window.twD.err==0) {
		_getBody();
		$().twdialog("close");
	}
});

//提交
$(".twdialog_button input:eq(0)").click(function(){ $("form:first").submit(); });

$("#add").click(function(){
	$("form:first").attr("action", "?mod=category&action=model&do=ajax_add");
	$("#add_edit input").val("");
	$().twdialog("open");
});

function _getBody() {
	twAjax.get("?mod=category&action=model&do=ajax_get_tbody&r="+time(), function(data){
		$(".tb2 tbody").html(data);
		_loadFunc();
	});
}

function _loadFunc() {
	$(".field,.edit,.del").attr("href","javascript:;");
	//编辑
	$(".edit").click(function(){
		var mid = $(this).parent().parent().find("td:eq(0)").html();
		$("form:first").attr("action", "?mod=category&action=model&do=ajax_edit&mid="+mid);
		$(".twdialog_title span").html("编辑模型");
		twAjax.loading();
		twAjax.get("?mod=category&action=model&do=ajax_get_mid&mid="+mid+"&r="+time(), function(data){
			data = toJson(data);
			$("#add_edit input[name='name']").val(data.name);
			$("#add_edit input[name='tablename']").val(data.tablename);
			$().twdialog("open");
			twAjax.remove();
		});
	});

	//删除
	$(".del").click(function(){
		var obj = $(this).parent().parent();
		twAjax.confirm("删除不可恢复，确定删除？", function(){
			twAjax.postd("?mod=category&action=model&do=ajax_del", {"mid":obj.find("td:eq(0)").html()}, function(data){
				twAjax.alert(data);
				if(window.twD.err==0) {
					obj.remove();
				}
			});
		});
	});
}
</script>
</body>
</html>